package org.justframework.util;



/**
 * string util
 * 
 */
public class StringUtil {

	/**
	 * check blank without trim
	 * 
	 * @param value
	 * @return
	 */
	public static boolean isBlank(String value) {
		return "".equals(value);
	}
	
	/**
	 * check blank with trim
	 * 
	 * @param value
	 * @return
	 */
	public static boolean isBlankWithTrim(String value) {
		if(value == null){
			return false;
		}
		return "".equals(value.trim());
	}

	/**
	 * check null
	 * 
	 * @param value
	 * @return
	 */
	public static boolean isNull(String value) {
		return value == null ? true : false;
	}
	
	/**
	 * check null or blank without trim
	 * 
	 * @param value
	 * @return
	 */
	public static boolean isNullOrBlank(String value) {
		return isNull(value) || isBlank(value);
	}
	
	/**
	 * get camel style string，eg. last_action_time -> lastActionTime 
	 * @param str
	 * @return
	 */
	public static String getCamelCaseString(String str){
		if(str == null){
			return "";
		}
		str = str.toLowerCase();
		StringBuilder result = new StringBuilder(str.length());
		boolean toCapitalize = false;
		for (int i = 0; i < str.length(); i++)
		{
		  char c = str.charAt(i);
		  if((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')){
		    if (toCapitalize){
		      result.append(Character.toUpperCase(c));
		      toCapitalize = false;
		    } else {
		      result.append(c);
		    }
		  } else {
			  toCapitalize = true;
		  }
		}
		return result.toString();
	}
	
}
